package com.example.sqlitedemo;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {

	private static final String tag = "DataBaseHelper";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		DataBaseHelper dbHelper = new DataBaseHelper(this);
		
		SQLiteDatabase db = dbHelper.getReadableDatabase();
		
		String query = "SELECT * FROM " + DataBaseHelper.TABLE_NAME + " ORDER BY " +
						DataBaseHelper.COLUMN_NAME_FIRSTNAME;
		
		Cursor cursor = db.rawQuery(query, null);
		
		if(cursor.moveToFirst()) {
			do {
				Log.d(tag, "First Name: " + cursor.getString(0));
				Log.d(tag, "Last Name: " + cursor.getString(1));
				Log.d(tag, "ID: " + cursor.getInt(2));
			} while (cursor.moveToNext());
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
